package com.engine.controller;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.entity.UfDjfbjgVo;
import dm.jdbc.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @version 1.0
 * @Title ecology-9
 * @Company 泛微软件
 * @CreateDate 2023/12/14
 * @Description 等级计算Controller
 * @Author AdminZm
 */
public class GradeCountController {

    BaseBean baseBean = new BaseBean();

    @POST
    @Path("/gradeCount")
    @Produces(MediaType.APPLICATION_JSON)
    public String gradeCount(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> params = ParamUtil.request2Map(request);
        Object jobgroupid = params.get("jobgroupid");
        Map<String, String> resultMap = new HashMap<>();
        try {
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            rs.executeQuery("SELECT * FROM uf_djfbbl WHERE jxkhjh = ?", jobgroupid);
            String aplusdbl = null;
            String aplusqzbs = null;
            String aplusjssx = null;
            String adbl = null;
            String aqzbs = null;
            String ajssx = null;
            String bdbl = null;
            String bqzbs = null;
            String bjssx = null;
            String cdbl = null;
            String cqzbs = null;
            String cjssx = null;
            String ddbl = null;
            String dqzbs = null;
            String djssx = null;
            if (rs.next()) {
                aplusdbl = rs.getString("aplusdbl");
                aplusqzbs = rs.getString("aplusqzbs");
                aplusjssx = rs.getString("aplusjssx");
                if (StringUtils.isEmpty(aplusjssx)) {
                    aplusjssx = "1";
                }
                adbl = rs.getString("adbl");
                aqzbs = rs.getString("aqzbs");
                ajssx = rs.getString("ajssx");
                if (StringUtils.isEmpty(ajssx)) {
                    ajssx = "1";
                }
                bdbl = rs.getString("bdbl");
                bqzbs = rs.getString("bqzbs");
                bjssx = rs.getString("bjssx");
                if (StringUtils.isEmpty(bjssx)) {
                    bjssx = "1";
                }
                cdbl = rs.getString("cdbl");
                cqzbs = rs.getString("cqzbs");
                cjssx = rs.getString("cjssx");
                if (StringUtils.isEmpty(cjssx)) {
                    cjssx = "1";
                }
                ddbl = rs.getString("ddbl");
                dqzbs = rs.getString("dqzbs");
                djssx = rs.getString("djssx");
                if (StringUtils.isEmpty(djssx)) {
                    djssx = "1";
                }
            } else {
                resultMap.put("code", "400");
                resultMap.put("msg", "等级分布比例及取整逻辑获取失败，请检查！");
                return JSONObject.toJSONString(resultMap);
            }
            if (StringUtil.isEmpty(aplusdbl) || StringUtil.isEmpty(adbl) || StringUtil.isEmpty(bdbl) || StringUtil.isEmpty(cdbl) || StringUtil.isEmpty(aplusqzbs)
                    || StringUtil.isEmpty(aqzbs) || StringUtil.isEmpty(bqzbs) || StringUtil.isEmpty(cqzbs) || StringUtil.isEmpty(dqzbs)) {
                resultMap.put("code", "400");
                resultMap.put("msg", "等级分布比例及取整逻辑设置有误，请重新设置！");
                return JSONObject.toJSONString(resultMap);
            }

            Map<String, Integer> jssxMap = new HashMap<>();
            jssxMap.put("0", Integer.parseInt(aplusjssx));
            jssxMap.put("1", Integer.parseInt(ajssx));
            jssxMap.put("2", Integer.parseInt(bjssx));
            jssxMap.put("3", Integer.parseInt(cjssx));
            jssxMap.put("4", Integer.parseInt(djssx));
            Map<String, Integer> jssxMapNew = jssxMap.entrySet().stream()
                    .sorted(Map.Entry.<String, Integer>comparingByValue()) // 按照value排序
                    .collect(Collectors.toMap(
                            Map.Entry::getKey,       // key提取器
                            Map.Entry::getValue,      // value提取器
                            (oldValue, newValue) -> oldValue, // 如果key冲突，保留旧值
                            LinkedHashMap::new       // 使用LinkedHashMap保持插入顺序
                    ));
            baseBean.writeLog("jssxMapNew is:" + JSONObject.toJSONString(jssxMapNew));
            List<String> sxList = new ArrayList<>();
            jssxMapNew.forEach((k,v)->{
                sxList.add(k);
            });
            baseBean.writeLog("sxList is:" + sxList);
            BigDecimal aplusdblD = new BigDecimal(aplusdbl);
            BigDecimal adblD = new BigDecimal(adbl);
            BigDecimal bdblD = new BigDecimal(bdbl);
            BigDecimal cdblD = new BigDecimal(cdbl);
            BigDecimal ddblD = new BigDecimal(ddbl);

            List<UfDjfbjgVo> ufDjfbjgVoList = new ArrayList<>();

            rs.executeQuery("SELECT a.*, b.companyworkyear FROM uf_djfbjg a left join hrmresource b on a.xm = b.id where a.jxkhjh = ?", jobgroupid);
            while (rs.next()) {
                UfDjfbjgVo ufDjfbjgVo = new UfDjfbjgVo();
                int id = rs.getInt("id");
                int xm = rs.getInt("xm");
                int jxkhjh = rs.getInt("jxkhjh");
                String ywxStr = rs.getString("ywx");
                if (StringUtils.isEmpty(ywxStr)) {
                    String ygName = "";
                    rs1.executeQuery("select lastname from hrmresource where id = ?", xm);
                    if (rs1.next()) {
                        ygName = rs1.getString("lastname");
                    }
                    resultMap.put("code", "400");
                    resultMap.put("msg", "请设置员工 " + ygName + " 的业务线！");
                    return JSONObject.toJSONString(resultMap);
                }
                String fp2 = rs.getString("fp2");
                String crbs = rs.getString("crbs");
                String companyworkyear = rs.getString("companyworkyear");
                if (StringUtils.isEmpty(companyworkyear)) {
                    companyworkyear = "0";
                }
                ufDjfbjgVo.setId(id);
                ufDjfbjgVo.setXm(xm);
                ufDjfbjgVo.setJxkhjh(jxkhjh);
                ufDjfbjgVo.setYwx(Integer.parseInt(ywxStr));
                ufDjfbjgVo.setFp2(Double.parseDouble(fp2));
                ufDjfbjgVo.setWorkYear(Double.parseDouble(companyworkyear));
                ufDjfbjgVo.setCrbs(crbs);
                ufDjfbjgVoList.add(ufDjfbjgVo);
            }
            if (CollectionUtils.isEmpty(ufDjfbjgVoList)) {
                resultMap.put("code", "400");
                resultMap.put("msg", "没有数据需要计算！");
                return JSONObject.toJSONString(resultMap);
            }

            Map<Integer, List<UfDjfbjgVo>> ufDjfbjgVoListMapB = ufDjfbjgVoList.stream()
                    .collect(Collectors.groupingBy(UfDjfbjgVo :: getYwx));
            baseBean.writeLog("ufDjfbjgVoListMapB size:" + ufDjfbjgVoListMapB.size());
            for (Map.Entry<Integer, List<UfDjfbjgVo>> entryB : ufDjfbjgVoListMapB.entrySet()) {
                List<UfDjfbjgVo> ufDjfbjgVoListB = entryB.getValue();
                if (CollectionUtils.isEmpty(ufDjfbjgVoListB)) {
                    continue;
                }
                List<UfDjfbjgVo> ufDjfbjgVoDepartList = new ArrayList<>();
                List<UfDjfbjgVo> ufDjfbjgVoDepartOtherList = new ArrayList<>();
                for (UfDjfbjgVo ufDjfbjgVoTempA : ufDjfbjgVoListB) {
                    String crbs = ufDjfbjgVoTempA.getCrbs();
                    if (StringUtils.isNotEmpty(crbs) && StringUtils.equals(crbs, "0")) {
                        ufDjfbjgVoDepartList.add(ufDjfbjgVoTempA);
                    } else {
                        ufDjfbjgVoDepartOtherList.add(ufDjfbjgVoTempA);
                    }
                }
                baseBean.writeLog("start to handle depart data.");
                if (!CollectionUtils.isEmpty(ufDjfbjgVoDepartList)) {
                    baseBean.writeLog("ufDjfbjgVoDepartList:" + ufDjfbjgVoDepartList.size());
                    int size = ufDjfbjgVoListB.size();
                    Integer ddjSize = 0;
                    if (StringUtils.equals(dqzbs, "0")) {
                        ddjSize = ddblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
                    }
                    if (StringUtils.equals(dqzbs, "1")) {
                        ddjSize = ddblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
                    }

                    ufDjfbjgVoDepartList = ufDjfbjgVoDepartList.stream().sorted(Comparator.comparing(UfDjfbjgVo::getWorkYear))
                            .collect(Collectors.toList());
                    baseBean.writeLog("ufDjfbjgVoDepartList is:" + JSONObject.toJSONString(ufDjfbjgVoDepartList));
                    int index = 1;
                    for (UfDjfbjgVo ufDjfbjgVoTemp : ufDjfbjgVoDepartList) {
                        if (index <= ddjSize) {
                            rs.executeUpdate("UPDATE uf_djfbjg SET dj = ? WHERE id = ?", 4, ufDjfbjgVoTemp.getId());
                        } else {
                            rs.executeUpdate("UPDATE uf_djfbjg SET dj = ? WHERE id = ?", 3, ufDjfbjgVoTemp.getId());
                        }
                        index = index + 1;
                    }
                }

                baseBean.writeLog("start to handle other data.");
                if (!CollectionUtils.isEmpty(ufDjfbjgVoDepartOtherList)) {
                    baseBean.writeLog("ufDjfbjgVoDepartOtherList:" + ufDjfbjgVoDepartOtherList.size());
                    for (UfDjfbjgVo ufDjfbjgVoTemp : ufDjfbjgVoDepartOtherList) {
                        rs.executeUpdate("UPDATE uf_djfbjg SET dj = ? WHERE id = ?", 2, ufDjfbjgVoTemp.getId());
                    }
                }
            }
//            RecordSet rsUpdate = new RecordSet();
//            String sqlUpdate = "UPDATE uf_djfbjg SET dj = ? WHERE id = ?";
//            if ((!CollectionUtils.isEmpty(ufDjfbjgVoList)) && ufDjfbjgVoList.size() > 0) {
//                Map<Integer, List<UfDjfbjgVo>> ufDjfbjgVoListMapA = ufDjfbjgVoList.stream()
//                        .collect(Collectors.groupingBy(UfDjfbjgVo :: getJxkhjh));
//                for (Map.Entry<Integer, List<UfDjfbjgVo>> entryA : ufDjfbjgVoListMapA.entrySet()) {
//                    List<UfDjfbjgVo> ufDjfbjgVoListA = entryA.getValue();
//                    if (CollectionUtils.isEmpty(ufDjfbjgVoListA)) {
//                        continue;
//                    }
//                    Map<Integer, List<UfDjfbjgVo>> ufDjfbjgVoListMapB = ufDjfbjgVoListA.stream()
//                            .collect(Collectors.groupingBy(UfDjfbjgVo :: getYwx));
//                    for (Map.Entry<Integer, List<UfDjfbjgVo>> entryB : ufDjfbjgVoListMapB.entrySet()) {
//                        List<UfDjfbjgVo> ufDjfbjgVoListB = entryB.getValue();
//                        if (CollectionUtils.isEmpty(ufDjfbjgVoListB)) {
//                            continue;
//                        }
//                        ufDjfbjgVoListB = ufDjfbjgVoListB.stream().sorted(Comparator.comparing(UfDjfbjgVo::getFp2).reversed())
//                                .collect(Collectors.toList());
//                        int size = ufDjfbjgVoListB.size();
//                        int index = 0;
//                        Integer indexAPlus = aplusdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
//                        for (int i = 0; i < indexAPlus; i++) {
//                            if (i >= size) {
//                                continue;
//                            }
//                            int idTemp = ufDjfbjgVoListB.get(i).getId();
//                            rsUpdate.executeUpdate(sqlUpdate, 0, idTemp);
//                        }
//                        if (indexAPlus > size) {
//                            continue;
//                        }
//                        Integer indexA = adblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
//                        index = indexAPlus + indexA;
//                        for (int i = indexAPlus; i < index; i++) {
//                            if (i >= size) {
//                                continue;
//                            }
//                            int idTemp = ufDjfbjgVoListB.get(i).getId();
//                            rsUpdate.executeUpdate(sqlUpdate, 1, idTemp);
//                        }
//                        if (index > size) {
//                            continue;
//                        }
//                        Integer indexB = bdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
//                        int indexN = index + indexB;
//                        for (int i = index; i < indexN; i++) {
//                            if (i >= size) {
//                                continue;
//                            }
//                            int idTemp = ufDjfbjgVoListB.get(i).getId();
//                            rsUpdate.executeUpdate(sqlUpdate, 2, idTemp);
//                        }
//                        if (indexN > size) {
//                            continue;
//                        }
//                        Integer indexC = cdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
//                        int indexNN = indexN + indexC;
//                        for (int i = indexN; i < indexNN; i++) {
//                            if (i >= size) {
//                                continue;
//                            }
//                            int idTemp = ufDjfbjgVoListB.get(i).getId();
//                            rsUpdate.executeUpdate(sqlUpdate, 3, idTemp);
//                        }
//                        if (indexNN > size) {
//                            continue;
//                        }
//                        for (int i = indexNN; i < size; i++) {
//                            int idTemp = ufDjfbjgVoListB.get(i).getId();
//                            rsUpdate.executeUpdate(sqlUpdate, 4, idTemp);
//                        }
//                    }
//                }
//                resultMap.put("code", "200");
//                resultMap.put("msg", "计算完成！");
//            }

            // 同步层级人数数据
            baseBean.writeLog("start to handle cj data.");
            RecordSet rs2 = new RecordSet();
            String cjfbrsModeId = baseBean.getPropValue("ss_prop_zm", "cjfbrs_mode_id");
            String cjfbrsQueryId = baseBean.getPropValue("ss_prop_zm", "cjfbrs_query_id");
            String insertSql = "INSERT INTO uf_cjfbrs (szkhjh,ywx,cj,rs,formmodeid) values (?,?,?,?,?)";
            for (Map.Entry<Integer, List<UfDjfbjgVo>> entryB : ufDjfbjgVoListMapB.entrySet()) {
                Integer key = entryB.getKey();
                List<UfDjfbjgVo> ufDjfbjgVoListB = entryB.getValue();
                if (CollectionUtils.isEmpty(ufDjfbjgVoListB)) {
                    continue;
                }
                int size = ufDjfbjgVoListB.size();
                baseBean.writeLog("size、aplusdblD:" + size + "、" + aplusdblD);
                Integer aplusdjSize = 0;
                Integer adjSize = 0;
                Integer bdjSize = 0;
                Integer cdjSize = 0;
                Integer ddjSize = 0;
                for (int i = 0; i < sxList.size(); i++) {
                    String signKey = sxList.get(i);
                    if (i < sxList.size() - 1) {
                        if (StringUtils.equals(signKey, "0")) {
                            if (StringUtils.equals(aplusqzbs, "0")) {
                                aplusdjSize = aplusdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
                            }
                            if (StringUtils.equals(aplusqzbs, "1")) {
                                aplusdjSize = aplusdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
                            }
                            baseBean.writeLog("aplusdjSize is:" + aplusdjSize + "、" + adjSize + "、" + bdjSize + "、" + cdjSize + "、" + ddjSize);
                            if ((aplusdjSize + adjSize + bdjSize + cdjSize + ddjSize) > size) {
                                aplusdjSize = size - (adjSize + bdjSize + cdjSize + ddjSize);
                                if (aplusdjSize < 0) {
                                    aplusdjSize = 0;
                                }
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "0");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", aplusdjSize, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "0", aplusdjSize, cjfbrsModeId);
                            }
                        }
                        if (StringUtils.equals(signKey, "1")) {
                            if (StringUtils.equals(aqzbs, "0")) {
                                adjSize = adblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
                            }
                            if (StringUtils.equals(aqzbs, "1")) {
                                adjSize = adblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
                            }
                            baseBean.writeLog("adjSize is:" + aplusdjSize + "、" + adjSize + "、" + bdjSize + "、" + cdjSize + "、" + ddjSize);
                            if ((aplusdjSize + adjSize + bdjSize + cdjSize + ddjSize) > size) {
                                adjSize = size - (aplusdjSize + bdjSize + cdjSize + ddjSize);
                                if (adjSize < 0) {
                                    adjSize = 0;
                                }
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "1");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", adjSize, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "1", adjSize, cjfbrsModeId);
                            }
                        }
                        if (StringUtils.equals(signKey, "2")) {
                            if (StringUtils.equals(bqzbs, "0")) {
                                bdjSize = bdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
                            }
                            if (StringUtils.equals(bqzbs, "1")) {
                                bdjSize = bdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
                            }
                            baseBean.writeLog("bdjSize is:" + aplusdjSize + "、" + adjSize + "、" + bdjSize + "、" + cdjSize + "、" + ddjSize);
                            if ((aplusdjSize + adjSize + bdjSize + cdjSize + ddjSize) > size) {
                                bdjSize = size - (aplusdjSize + adjSize + cdjSize + ddjSize);
                                if (bdjSize < 0) {
                                    bdjSize = 0;
                                }
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "2");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", bdjSize, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "2", bdjSize, cjfbrsModeId);
                            }
                        }
                        if (StringUtils.equals(signKey, "3")) {
                            if (StringUtils.equals(cqzbs, "0")) {
                                cdjSize = cdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
                            }
                            if (StringUtils.equals(cqzbs, "1")) {
                                cdjSize = cdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
                            }
                            baseBean.writeLog("cdjSize is:" + aplusdjSize + "、" + adjSize + "、" + bdjSize + "、" + cdjSize + "、" + ddjSize);
                            if ((aplusdjSize + adjSize + bdjSize + cdjSize + ddjSize) > size) {
                                cdjSize = size - (aplusdjSize + bdjSize + adjSize + ddjSize);
                                if (cdjSize < 0) {
                                    cdjSize = 0;
                                }
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "3");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", cdjSize, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "3", cdjSize, cjfbrsModeId);
                            }
                        }
                        if (StringUtils.equals(signKey, "4")) {
                            if (StringUtils.equals(dqzbs, "0")) {
                                ddjSize = ddblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
                            }
                            if (StringUtils.equals(dqzbs, "1")) {
                                ddjSize = ddblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
                            }
                            baseBean.writeLog("ddjSize is:" + aplusdjSize + "、" + adjSize + "、" + bdjSize + "、" + cdjSize + "、" + ddjSize);
                            if ((aplusdjSize + adjSize + bdjSize + cdjSize + ddjSize) > size) {
                                ddjSize = size - (aplusdjSize + bdjSize + cdjSize + adjSize);
                                if (ddjSize < 0) {
                                    ddjSize = 0;
                                }
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "4");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", ddjSize, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "4", ddjSize, cjfbrsModeId);
                            }
                        }
                    } else {
                        // 最后一个特殊计算
                        if (StringUtils.equals(signKey, "0")) {
                            Integer aplusdjSizeTemp = size - bdjSize - adjSize - cdjSize - ddjSize;
                            if (aplusdjSizeTemp < 0) {
                                aplusdjSizeTemp = 0;
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "0");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", aplusdjSizeTemp, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "0", aplusdjSizeTemp, cjfbrsModeId);
                            }
                        }
                        if (StringUtils.equals(signKey, "1")) {
                            Integer sizeTemp = size - bdjSize - aplusdjSize - cdjSize - ddjSize;
                            if (sizeTemp < 0) {
                                sizeTemp = 0;
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "1");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", sizeTemp, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "1", sizeTemp, cjfbrsModeId);
                            }
                        }
                        if (StringUtils.equals(signKey, "2")) {
                            Integer sizeTemp = size - adjSize - aplusdjSize - cdjSize - ddjSize;
                            if (sizeTemp < 0) {
                                sizeTemp = 0;
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "2");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", sizeTemp, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "2", sizeTemp, cjfbrsModeId);
                            }
                        }
                        if (StringUtils.equals(signKey, "3")) {
                            Integer sizeTemp = size - bdjSize - aplusdjSize - adjSize - ddjSize;
                            if (sizeTemp < 0) {
                                sizeTemp = 0;
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "3");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", sizeTemp, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "3", sizeTemp, cjfbrsModeId);
                            }
                        }
                        if (StringUtils.equals(signKey, "4")) {
                            Integer sizeTemp = size - bdjSize - aplusdjSize - cdjSize - adjSize;
                            if (sizeTemp < 0) {
                                sizeTemp = 0;
                            }
                            rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "4");
                            if (rs.next()) {
                                String idTemp = rs.getString("id");
                                rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", sizeTemp, idTemp);
                            } else {
                                rs2.executeUpdate(insertSql, jobgroupid, key, "4", sizeTemp, cjfbrsModeId);
                            }
                        }
                    }
                }

//                Integer bdjSize = 0;
//                if (StringUtils.equals(bqzbs, "0")) {
//                    bdjSize = bdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
//                }
//                if (StringUtils.equals(bqzbs, "1")) {
//                    bdjSize = bdblD.multiply(new BigDecimal(String.valueOf(size))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
//                }
//                rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "2");
//                if (rs.next()) {
//                    String idTemp = rs.getString("id");
//                    rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", bdjSize, idTemp);
//                } else {
//                    rs2.executeUpdate(insertSql, jobgroupid, key, "2", bdjSize, cjfbrsModeId);
//                }


                // B等级特殊处理
//                Integer bdjSize = size - aplusdjSize - adjSize - cdjSize - ddjSize;
//                if (bdjSize < 0) {
//                    bdjSize = 0;
//                }
//                rs.executeQuery("SELECT id FROM uf_cjfbrs WHERE szkhjh = ? AND ywx = ? AND cj = ?", jobgroupid, key, "2");
//                if (rs.next()) {
//                    String idTemp = rs.getString("id");
//                    rs2.executeUpdate("UPDATE uf_cjfbrs SET rs = ? where id = ?", bdjSize, idTemp);
//                } else {
//                    rs2.executeUpdate(insertSql, jobgroupid, key, "2", bdjSize, cjfbrsModeId);
//                }
            }
            //权限重构
            ModeRightInfo ModeRightInfo = new ModeRightInfo();
            ModeRightInfo.setNewRight(true);
            ModeRightInfo.editModeDataShare(1, Integer.parseInt(cjfbrsModeId), Integer.parseInt(cjfbrsQueryId));

            resultMap.put("code", "200");
            resultMap.put("msg", "计算完成！");
        } catch (Exception e) {
            resultMap.put("code", "500");
            resultMap.put("msg", "系统错误，请联系管理员！");
            baseBean.writeLog("gradeCount error:" + e.getMessage());
        }
        return JSONObject.toJSONString(resultMap);
    }

    @POST
    @Path("/addDepartPerson")
    @Produces(MediaType.APPLICATION_JSON)
    public String addDepartPerson(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> params = ParamUtil.request2Map(request);
        Object jobgroupid = params.get("jobgroupid");
        Map<String, String> resultMap = new HashMap<>();
        try {
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            rs.executeQuery("SELECT * FROM uf_djfbbl WHERE jxkhjh = ?", jobgroupid);
            String sznd = null;
            if (rs.next()) {
                sznd = rs.getString("sznd");
            }
            if (StringUtil.isEmpty(sznd)) {
                resultMap.put("code", "400");
                resultMap.put("msg", "等级分布比例所属年度设置有误，请重新设置！");
                return JSONObject.toJSONString(resultMap);
            }

            Set<String> xmSet = new HashSet<>();
            rs.executeQuery("SELECT * FROM uf_djfbjg where jxkhjh = ?", jobgroupid);
            while (rs.next()) {
                String xm = rs.getString("xm");
                xmSet.add(xm);
            }
            String notNeedUsekindId = baseBean.getPropValue("ss_prop_zm", "not_need_usekind_id");
            rs.executeQuery("SELECT * FROM hrmresource where status = 5 and usekind not in (" + notNeedUsekindId + ") and enddate is not null and DATEPART(YEAR, enddate) = ?", sznd);

            String finalDjModeId = baseBean.getPropValue("ss_prop_zm", "final_dj_mode_id");
            String modedatacreater = "1";
            String modedatacreatertype = "0";
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");//设置日期格式
            String nowDate = sdfDate.format(new Date());
            String nowTime = sdfTime.format(new Date());
            List<List> insertParams = new ArrayList<>();
            String insertSql = "INSERT INTO uf_djfbjg (xm, bm, jxkhjh, ywx, zp, fp1, fp2, MODEUUID, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime, formmodeid, crbs) " +
                    "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            List<String> uuidList = new ArrayList<>();
            while (rs.next()) {
                String id = rs.getString("id");
                String departmentid = rs.getString("departmentid");
                if (CollectionUtils.isEmpty(xmSet) || !xmSet.contains(id)) {
                    String uuid = UUID.randomUUID().toString();
                    String ywx = null;
                    rs1.executeQuery("select top 1 ywx from uf_djfbjg where xm = ? ORDER BY id DESC", id);
                    if (rs1.next()) {
                        ywx = rs1.getString("ywx");
                    }
                    List rowParam = new ArrayList<>();
                    rowParam.add(id);
                    rowParam.add(departmentid);
                    rowParam.add(jobgroupid);
                    rowParam.add(ywx);
                    rowParam.add("0.0");
                    rowParam.add("0.0");
                    rowParam.add("0.0");
                    rowParam.add(uuid);
                    rowParam.add(modedatacreater);
                    rowParam.add(modedatacreatertype);
                    rowParam.add(nowDate);
                    rowParam.add(nowTime);
                    rowParam.add(finalDjModeId);
                    rowParam.add("0");
                    insertParams.add(rowParam);
                    uuidList.add(uuid);
                }
            }
            if (!CollectionUtils.isEmpty(insertParams)) {
                rs.executeBatchSql(insertSql, insertParams);
            }
            // 权限重构
            if (!CollectionUtils.isEmpty(uuidList)) {
                ModeRightInfo ModeRightInfo = new ModeRightInfo();
                ModeRightInfo.setNewRight(true);
                for (String u : uuidList) {
                    rs.executeQuery("select id from uf_djfbjg where MODEUUID = ?", u);
                    if (rs.next()) {
                        String idTemp = rs.getString("id");
                        if (StringUtils.isNotEmpty(idTemp)) {
                            ModeRightInfo.editModeDataShare(1, Integer.parseInt(finalDjModeId), Integer.parseInt(idTemp));
                        }
                    }
                }
            }

            resultMap.put("code", "200");
            resultMap.put("msg", "添加完成！");
        } catch (Exception e) {
            resultMap.put("code", "500");
            resultMap.put("msg", "系统错误，请联系管理员！");
            baseBean.writeLog("gradeCount error:" + e.getMessage());
        }
        return JSONObject.toJSONString(resultMap);
    }

    @POST
    @Path("/addOtherDepartPerson")
    @Produces(MediaType.APPLICATION_JSON)
    public String addOtherDepartPerson(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        Map<String, Object> params = ParamUtil.request2Map(request);
        Object jobgroupid = params.get("jobgroupid");
        Map<String, String> resultMap = new HashMap<>();
        try {
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            rs.executeQuery("SELECT * FROM uf_djfbbl WHERE jxkhjh = ?", jobgroupid);
            String sznd = null;
            if (rs.next()) {
                sznd = rs.getString("sznd");
            }
            if (StringUtil.isEmpty(sznd)) {
                resultMap.put("code", "400");
                resultMap.put("msg", "等级分布比例所属年度设置有误，请重新设置！");
                return JSONObject.toJSONString(resultMap);
            }

            Set<String> xmSet = new HashSet<>();
            rs.executeQuery("SELECT xm FROM uf_djfbjg where jxkhjh = ?", jobgroupid);
            while (rs.next()) {
                String xm = rs.getString("xm");
                xmSet.add(xm);
            }
            String notNeedUsekindId = baseBean.getPropValue("ss_prop_zm", "not_need_usekind_id");
            rs.executeQuery("SELECT * FROM hrmresource where usekind not in (" + notNeedUsekindId + ") and ((status = 5 and enddate is not null and DATEPART(YEAR, enddate) > ?) or (status != 5))", sznd);

            String finalDjModeId = baseBean.getPropValue("ss_prop_zm", "final_dj_mode_id");
            String modedatacreater = "1";
            String modedatacreatertype = "0";
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");//设置日期格式
            String nowDate = sdfDate.format(new Date());
            String nowTime = sdfTime.format(new Date());
            List<List> insertParams = new ArrayList<>();
            String insertSql = "INSERT INTO uf_djfbjg (xm, bm, jxkhjh, ywx, zp, fp1, fp2, MODEUUID, modedatacreater, modedatacreatertype, modedatacreatedate, modedatacreatetime, formmodeid, crbs) " +
                    "VALUES (?,?,?,?,?,?,?, ?,?,?,?,?,?,?)";
            List<String> uuidList = new ArrayList<>();
            while (rs.next()) {
                String id = rs.getString("id");
                String departmentid = rs.getString("departmentid");
                if (CollectionUtils.isEmpty(xmSet) || !xmSet.contains(id)) {
                    String uuid = UUID.randomUUID().toString();
                    String ywx = null;
                    rs1.executeQuery("select top 1 ywx from uf_djfbjg where xm = ? ORDER BY id DESC", id);
                    if (rs1.next()) {
                        ywx = rs1.getString("ywx");
                    }
                    List rowParam = new ArrayList<>();
                    rowParam.add(id);
                    rowParam.add(departmentid);
                    rowParam.add(jobgroupid);
                    rowParam.add(ywx);
                    rowParam.add("0.0");
                    rowParam.add("0.0");
                    rowParam.add("0.0");
                    rowParam.add(uuid);
                    rowParam.add(modedatacreater);
                    rowParam.add(modedatacreatertype);
                    rowParam.add(nowDate);
                    rowParam.add(nowTime);
                    rowParam.add(finalDjModeId);
                    rowParam.add("1");
                    insertParams.add(rowParam);
                    uuidList.add(uuid);
                }
            }
            if (!CollectionUtils.isEmpty(insertParams)) {
                rs.executeBatchSql(insertSql, insertParams);
            }
            // 权限重构
            if (!CollectionUtils.isEmpty(uuidList)) {
                ModeRightInfo ModeRightInfo = new ModeRightInfo();
                ModeRightInfo.setNewRight(true);
                for (String u : uuidList) {
                    rs.executeQuery("select id from uf_djfbjg where MODEUUID = ?", u);
                    if (rs.next()) {
                        String idTemp = rs.getString("id");
                        if (StringUtils.isNotEmpty(idTemp)) {
                            ModeRightInfo.editModeDataShare(1, Integer.parseInt(finalDjModeId), Integer.parseInt(idTemp));
                        }
                    }
                }
            }

            resultMap.put("code", "200");
            resultMap.put("msg", "添加完成！");
        } catch (Exception e) {
            resultMap.put("code", "500");
            resultMap.put("msg", "系统错误，请联系管理员！");
            baseBean.writeLog("gradeCount error:" + e.getMessage());
        }
        return JSONObject.toJSONString(resultMap);
    }

    @GET
    @Path("/getDetailByType")
    @Produces(MediaType.APPLICATION_JSON)
    public String getDetailByType(@Context HttpServletRequest request, @Context HttpServletResponse response,
                                  @QueryParam("id") String id) {
        Map<Integer, List<UfDjfbjgVo>> resultListMap = new HashMap<>();
        RecordSet rs = new RecordSet();
        RecordSet rsA = new RecordSet();
        rs.executeQuery("SELECT a.*,b.requestname FROM uf_djfbjg a LEFT JOIN workflow_requestbase b ON a.nmjxkhlc =" +
                " b.requestid where a.jxkhjh = ?", id);
        while (rs.next()) {
            int xm = rs.getInt("xm");
            String xmName = null;
            rsA.executeQuery("SELECT lastname from hrmresource where id = ?", xm);
            if (rsA.next()) {
                xmName = rsA.getString("lastname");
            }
            int bm = rs.getInt("bm");
            String bmName = null;
            rsA.executeQuery("SELECT DEPARTMENTMARK from hrmdepartment where id = ?", bm);
            if (rsA.next()) {
                bmName = rsA.getString("DEPARTMENTMARK");
            }
            int jxkhjh = rs.getInt("jxkhjh");
            String jxkhjhName = null;
            rsA.executeQuery("select jxhdmcfrom uf_HRJX_KHJH where id = ?", jxkhjh);
            if (rsA.next()) {
                jxkhjhName = rsA.getString("jxhdmc");
            }
            int ywx = rs.getInt("ywx");
            int dj = rs.getInt("dj");
            String ywmbm = rs.getString("ywmbm");
            String zp = rs.getString("zp");
            String fp1 = rs.getString("fp1");
            String fp2 = rs.getString("fp2");
            String nmjxkhlc = rs.getString("nmjxkhlc");
            String requestname = rs.getString("requestname");
            UfDjfbjgVo ufDjfbjgVo = new UfDjfbjgVo();
            ufDjfbjgVo.setXm(xm);
            ufDjfbjgVo.setBm(bm);
            ufDjfbjgVo.setYwmbm(ywmbm);
            ufDjfbjgVo.setJxkhjh(jxkhjh);
            ufDjfbjgVo.setYwx(ywx);
            ufDjfbjgVo.setDj(dj);
            ufDjfbjgVo.setXmName(xmName);
            ufDjfbjgVo.setBmName(bmName);
            ufDjfbjgVo.setJxkhjhName(jxkhjhName);
            ufDjfbjgVo.setZp(zp);
            ufDjfbjgVo.setFp1(fp1);
            ufDjfbjgVo.setFp2(Double.parseDouble(fp2));
            if (StringUtils.isNotEmpty(nmjxkhlc)) {
                ufDjfbjgVo.setNmjxkhlc(nmjxkhlc);
            }
            if (StringUtils.isNotEmpty(requestname)) {
                ufDjfbjgVo.setNmjxkhlcmc(requestname);
            }
            int key = ywx + 1;
            if (resultListMap.containsKey(key)) {
                List<UfDjfbjgVo> ufDjfbjgVoList = resultListMap.get(key);
                ufDjfbjgVoList.add(ufDjfbjgVo);
                ufDjfbjgVoList = ufDjfbjgVoList.stream().sorted(Comparator.comparing(UfDjfbjgVo::getFp2).reversed())
                        .collect(Collectors.toList());
                resultListMap.put(key, ufDjfbjgVoList);
            } else {
                List<UfDjfbjgVo> ufDjfbjgVoList = new ArrayList<>();
                ufDjfbjgVoList.add(ufDjfbjgVo);
                resultListMap.put(key, ufDjfbjgVoList);
            }
        }
        return JSONObject.toJSONString(resultListMap);
    }

    @GET
    @Path("/getDjrsByType")
    @Produces(MediaType.APPLICATION_JSON)
    public String getDjrsByType(@Context HttpServletRequest request, @Context HttpServletResponse response,
                                @QueryParam("id") String id) {
        Map<String, Object> resultMap = new HashMap<>();
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        try {
            rs.executeQuery("SELECT * FROM uf_djfbjg where jxkhjh = ?", id);
            int ywx1rs = 0;
            int ywx2rs = 0;
            int ywx3rs = 0;
            int ywx4rs = 0;
            int ywx5rs = 0;
            while (rs.next()) {
                int ywx = rs.getInt("ywx");
                ywx = ywx + 1;
                if (ywx == 1) {
                    ywx1rs = ywx1rs + 1;
                }
                if (ywx == 2) {
                    ywx2rs = ywx2rs + 1;
                }
                if (ywx == 3) {
                    ywx3rs = ywx3rs + 1;
                }
                if (ywx == 4) {
                    ywx4rs = ywx4rs + 1;
                }
                if (ywx == 5) {
                    ywx5rs = ywx5rs + 1;
                }
            }

            rs1.executeQuery("SELECT * FROM uf_djfbbl WHERE jxkhjh = ?", id);
            String aplusdbl = null;
            String aplusqzbs = null;
            String adbl = null;
            String aqzbs = null;
            String bdbl = null;
            String bqzbs = null;
            String cdbl = null;
            String cqzbs = null;
            String ddbl = null;
            String dqzbs = null;
            if (rs1.next()) {
                aplusdbl = rs.getString("aplusdbl");
                aplusqzbs = rs.getString("aplusqzbs");
                if (StringUtils.isEmpty(aplusqzbs)) {
                    aplusqzbs = "0";
                }
                adbl = rs.getString("adbl");
                aqzbs = rs.getString("aqzbs");
                if (StringUtils.isEmpty(aqzbs)) {
                    aqzbs = "0";
                }
                bdbl = rs.getString("bdbl");
                bqzbs = rs.getString("bqzbs");
                if (StringUtils.isEmpty(bqzbs)) {
                    bqzbs = "0";
                }
                cdbl = rs.getString("cdbl");
                cqzbs = rs.getString("cqzbs");
                if (StringUtils.isEmpty(cqzbs)) {
                    cqzbs = "0";
                }
                ddbl = rs.getString("ddbl");
                dqzbs = rs.getString("dqzbs");
                if (StringUtils.isEmpty(dqzbs)) {
                    dqzbs = "0";
                }
            } else {
                resultMap.put("msg", "等级分布比例获取失败，请检查！");
                resultMap.put("code", "400");
                return JSONObject.toJSONString(resultMap);
            }
            BigDecimal aplusdblD = new BigDecimal(aplusdbl);
            BigDecimal adblD = new BigDecimal(adbl);
            BigDecimal bdblD = new BigDecimal(bdbl);
            BigDecimal cdblD = new BigDecimal(cdbl);
            BigDecimal ddblD = new BigDecimal(ddbl);
            Map<String, Object> dataMap = new HashMap<>();
            dataMap.put("site1", handleData(aplusdblD, aplusqzbs, adblD, aqzbs, bdblD, bqzbs, cdblD, cqzbs, ddblD, dqzbs, String.valueOf(ywx1rs)));
            dataMap.put("site2", handleData(aplusdblD, aplusqzbs, adblD, aqzbs, bdblD, bqzbs, cdblD, cqzbs, ddblD, dqzbs, String.valueOf(ywx2rs)));
            dataMap.put("site3", handleData(aplusdblD, aplusqzbs, adblD, aqzbs, bdblD, bqzbs, cdblD, cqzbs, ddblD, dqzbs, String.valueOf(ywx3rs)));
            dataMap.put("site4", handleData(aplusdblD, aplusqzbs, adblD, aqzbs, bdblD, bqzbs, cdblD, cqzbs, ddblD, dqzbs, String.valueOf(ywx4rs)));
            dataMap.put("site5", handleData(aplusdblD, aplusqzbs, adblD, aqzbs, bdblD, bqzbs, cdblD, cqzbs, ddblD, dqzbs, String.valueOf(ywx5rs)));
            resultMap.put("data", dataMap);
        } catch (Exception e) {
            baseBean.writeLog("getDjrsByType error:" + e.getMessage());
            resultMap.put("msg", "系统异常，请联系管理员！");
            resultMap.put("code", "500");
            return JSONObject.toJSONString(resultMap);
        }
        resultMap.put("code", "200");
        return JSONObject.toJSONString(resultMap);
    }

    public Map<String, String> handleData(BigDecimal aplusdblD, String aplusqzbs, BigDecimal adblD, String aqzbs, BigDecimal bdblD,
                                          String bqzbs, BigDecimal cdblD, String cqzbs, BigDecimal ddblD, String dqzbs, String allCount) {
        Map<String, String> resultMap = new HashMap<>();
        int aplusdjSize = 0;
        if (StringUtils.equals(aplusqzbs, "0")) {
            aplusdjSize = aplusdblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
        }
        if (StringUtils.equals(aplusqzbs, "1")) {
            aplusdjSize = aplusdblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
        }
        resultMap.put("Aplus", String.valueOf(aplusdjSize));

        int adjSize = 0;
        if (StringUtils.equals(aqzbs, "0")) {
            adjSize = adblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
        }
        if (StringUtils.equals(aqzbs, "1")) {
            adjSize = adblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
        }
        resultMap.put("A", String.valueOf(adjSize));

        int bdjSize = 0;
        if (StringUtils.equals(bqzbs, "0")) {
            bdjSize = bdblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
        }
        if (StringUtils.equals(bqzbs, "1")) {
            bdjSize = bdblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
        }
        resultMap.put("B", String.valueOf(bdjSize));

        int cdjSize = 0;
        if (StringUtils.equals(cqzbs, "0")) {
            cdjSize = cdblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
        }
        if (StringUtils.equals(cqzbs, "1")) {
            cdjSize = cdblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
        }
        resultMap.put("C", String.valueOf(cdjSize));

        int ddjSize = 0;
        if (StringUtils.equals(dqzbs, "0")) {
            ddjSize = ddblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.UP).intValue();
        }
        if (StringUtils.equals(dqzbs, "1")) {
            ddjSize = ddblD.multiply(new BigDecimal(String.valueOf(allCount))).divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
        }
        resultMap.put("D", String.valueOf(ddjSize));

        return resultMap;
    }
}
